'use strict';

module.exports = app => {
    const { INTEGER, STRING, DATE, BIGINT, BOOLEAN, DECIMAL } = app.Sequelize;

    const OrderVip = app.model.define('order_vip', {
        id: { type: BIGINT, primaryKey: true, autoIncrement: true },
        user_id: BIGINT,
        order_no: STRING(100),
        price: DECIMAL(10, 2),
        count: INTEGER,
        total_amount: DECIMAL(10, 2),
        payment: INTEGER,
        transaction_id: STRING(150),
        status: INTEGER,
        create_time: DATE,
        update_time: DATE,
        delete_time: DATE
    }, {
        defaultScope: {
          attributes: {
            exclude: [ 'delete_time', 'update_time' ],
          },
        },
        timestamps: true,
        paranoid: true,
        createdAt: 'create_time',
        updatedAt: 'update_time',
        deletedAt: 'delete_time'
    });

    OrderVip.associate = () => {
        app.model.OrderVip.belongsTo(app.model.User, {
            as: 'user',
            foreignKey: 'user_id',
            targetKey: 'id'
        })
    }

    return OrderVip;
}